package com.powernode.work.service.impl;

import com.powernode.commons.utils.DateUtils;
import com.powernode.commons.utils.ResponseData;
import com.powernode.commons.utils.UUIDUtils;
import com.powernode.work.bean.ClueRemarkBean;
import com.powernode.work.dao.ClueRemarkMapper;
import com.powernode.work.service.ClueRemarkService;
import com.powernode.work.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {
    @Autowired
    private ClueRemarkMapper dao;

    /**
     * 根据线索的id查询他的备注
     * @param clueId
     * @return
     */
    @Override
    public ResponseData getClueRemarkByClueId(String clueId) {
        return ResponseData.ok(dao.selectByClueId(clueId));
    }

    /**
     * 添加
     * @param remark
     * @return
     */
    @Override
    public ResponseData add(ClueRemarkBean remark) {
        //设置主键
        remark.setId(UUIDUtils.getUUID());
        //创建时间
        remark.setCreateTime(DateUtils.formatDateTime(new Date()));

        int row = dao.insertSelective(remark);
        if (row>0){
            return ResponseData.ok();
        }
        return ResponseData.error();
    }

    /**
     * 修改
     * @param remark
     * @return
     */
    @Override
    public ResponseData modify(ClueRemarkBean remark) {
        //设置修改人
        remark.setEditTime(DateUtils.formatDateTime(new Date()));
        int row = dao.updateByPrimaryKeySelective(remark);
        if (row>0){
            return ResponseData.ok();
        }
        return ResponseData.error();
    }
}
